home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dfpp01.zip / FOCUS.CPP < prev    next >
C/C++ Source or Header  |  1992-11-21  |  3KB  |  129 lines

  1. // ------------- focus.cpp
  2.  
  3. #include "dflatpp.h"
  4.  
  5. void DFWindow::CaptureFocus()
  6. {
  7.     if (this != desktop.FocusCapture())    {
  8.         if (desktop.FirstCapture() == NULL)
  9.             desktop.SetFirstCapture(desktop.InFocus());
  10.         prevcapture = desktop.FocusCapture();
  11.         desktop.SetFocusCapture(this);
  12.         SetFocus();
  13.     }
  14. }
  15.  
  16. void DFWindow::ReleaseFocus()
  17. {
  18.     if (this == desktop.FocusCapture())    {
  19.         desktop.SetFocusCapture(prevcapture);
  20.         prevcapture = NULL;
  21.         if (desktop.FocusCapture() == NULL)    {
  22.             if (desktop.FirstCapture() != NULL)
  23.                 desktop.FirstCapture()->SetFocus();
  24.             desktop.SetFirstCapture(NULL);
  25.         }
  26.         else
  27.             desktop.FocusCapture()->SetFocus();
  28.     }
  29. }
  30.  
  31. Bool DFWindow::SetFocus()
  32. {
  33.     if (this != desktop.InFocus())    {
  34.         if (desktop.InFocus() != NULL)
  35.             desktop.InFocus()->ResetFocus();
  36.         desktop.SetFocus(this);
  37.         Dequeue();        // move the window to the
  38.         Enqueue();        // top of the focus queue
  39.         Show();
  40.         // --- notify parent that child has taken the focus
  41.         if (parent != NULL)
  42.             parent->EnterFocus(this);
  43.     }
  44.     return True;
  45. }
  46.  
  47. void DFWindow::ResetFocus()
  48. {
  49.     if (parent != NULL)
  50.         // --- notify parent that child has relinquished the focus
  51.         parent->LeaveFocus(this);
  52.     desktop.SetFocus(NULL);
  53.     Border();
  54. }
  55.  
  56. // --- set the focus to the next eligible sibling window
  57. void DFWindow::NextSiblingFocus()
  58. {
  59.     DFWindow *Wnd = desktop.InFocus();
  60.     while (Wnd != NULL)    {
  61.         if (Wnd->next == NULL)    {
  62.             if (Wnd->parent != NULL)
  63.                 Wnd = Wnd->parent->first;
  64.         }
  65.         else
  66.             Wnd = Wnd->next;
  67.         if (Wnd == desktop.InFocus())
  68.             break;
  69.         if (Wnd != NULL)
  70.             if (Wnd->SetFocus())
  71.                 break;
  72.     }
  73. }
  74.  
  75. // --- set the focus to the next previous eligible sibling window
  76. void DFWindow::PrevSiblingFocus()
  77. {
  78.     DFWindow *Wnd = desktop.InFocus();
  79.     while (Wnd != NULL)    {
  80.         if (Wnd->prev == NULL)    {
  81.             if (Wnd->parent != NULL)
  82.                 Wnd = Wnd->parent->last;
  83.         }
  84.         else
  85.             Wnd = Wnd->prev;
  86.         if (Wnd == desktop.InFocus())
  87.             break;
  88.         if (Wnd != NULL)
  89.             if (Wnd->SetFocus())
  90.                 break;
  91.     }
  92. }
  93.  
  94. // --------- add the window to the linked list
  95. void DFWindow::Enqueue()
  96. {
  97.     next = prev = NULL;
  98.     if (parent != NULL)    {
  99.         if (parent->first == NULL)
  100.             parent->first = this;
  101.         prev = parent->last;
  102.         if (prev != NULL)
  103.             prev->next = this;
  104.         parent->last = this;
  105.     }
  106.     else if (desktop.ApplWnd() == NULL)
  107.         desktop.SetApplication(this);
  108. }
  109.  
  110. // --------- remove the window from the linked list
  111. void DFWindow::Dequeue()
  112. {
  113.     if (parent != NULL)    {
  114.         if (prev != NULL)
  115.             prev->next = next;
  116.         if (next != NULL)
  117.             next->prev = prev;
  118.         if (this == parent->first)
  119.             parent->first = next;
  120.         if (this == parent->last)
  121.             parent->last = prev;
  122.     }
  123.     else if (this == desktop.ApplWnd())
  124.         desktop.SetApplication(NULL);
  125. }
  126.  
  127.  
  128.  
  129.